#!/bin/sh 
# $Id: db2fo 61 2009-11-15 12:12:26Z ewe2 $
#
# db2fo, convert DocBook xml to pdf or postscript via fop

# Fink directory on OSX
#export DOCBOOK_XSL_HOME=/sw/share/xml/xsl/docbook-xsl

# docbook directory on Debian lenny
export DOCBOOK_XSL_HOME=/usr/share/xml/docbook/stylesheet/nwalsh

FO=0;

prog=`basename $0`
while [ $# -gt 0 ]
do
  case "$1" in
	 --ps)
	 FO=1;
	 shift
	 ;;
	--help)
	echo "Usage: $prog [OPTION]..."
	echo "Generate text or pdf from a docbook xml file, output to stdout"
	echo ""
	echo " --ps         generate postscript"
	echo " -h, --help      help"
	echo ""
	exit 0
	;;
	-*)
	echo "$prog: invalid option -- $1"
	echo "Try \`$prog --help' for more information."
	exit 1
	;;
	*)
	 arg=`echo "$1" | sed "s/'/'\"'\"'/g"`
	 shift
	 ;;
  esac
done


if [ $FO -eq 1 ];
then
	xsltproc -o `basename "$arg" .xml`.fo $DOCBOOK_XSL_HOME/fo/docbook.xsl $arg;
	fop `basename "$arg" .xml`.fo -ps `basename "$arg" .xml`.ps;
else
	xsltproc -o `basename "$arg" .xml`.fo $DOCBOOK_XSL_HOME/fo/docbook.xsl $arg;
	fop `basename "$arg" .xml`.fo `basename "$arg" .xml`.pdf;
fi
